package servicesImp.business;

import base.IBaseMapperWithoutBLOBs;
import base.IBaseServicesWithoutBLOBsImpl;
import exception.WTException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import services.business.BusinessInfoServices;
import services.business.ManagerAssessServices;
import wt.dao.business.ManagerAssessMapper;
import wt.entity.business.BusinessInfo;
import wt.entity.business.ManagerAssess;
import wt.entity.business.ManagerAssessExample;
import wt.staticData.ShortData;
import wt.staticData.TableName;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/10/14.
 */
@Service
public class ManagerAssessServicesImp extends IBaseServicesWithoutBLOBsImpl< ManagerAssess, ManagerAssessExample> implements ManagerAssessServices {
    @Autowired
    ManagerAssessMapper managerAssessMapper;
    @Autowired
    BusinessInfoServices businessInfoServices;

    @Override
    public IBaseMapperWithoutBLOBs< ManagerAssess, ManagerAssessExample> getMapper() {
        return this.managerAssessMapper;
    }

    @Override
    public String getTableName() {
        return TableName.BUS_MANAGER_ASSESS;
    }

    @Transactional
    public void insertSelective(List<ManagerAssess> managerAssessList, String businessId) throws Exception {
        BusinessInfo businessInfo = new BusinessInfo();
        businessInfo.setId(businessId);
        businessInfo.setManagerIsAssess(ShortData.s1);
        businessInfo.setManagerAssessTime(new Date());
        int count = businessInfoServices.updateByPrimaryKeySelective(businessInfo);

         if(count==1){
             for (ManagerAssess managerAssess : managerAssessList) {
                 getCurrentProxy().insertSelective(managerAssess);
             }
         }else{
            throw  new WTException(WTException.RECORD_NOT_FOUND) ;
         }


    }
}
